<?php

class db_adapter {
    private $dbh;
    
    public function __construct() { 
            
    }
    
    public function init($database, $user, $pswd) {
        $this->dbh = mysql_connect('localhost', $user, $pswd);
        if ($this->dbh === false) {
            echo "user $user pswd $pswd";
            echo " ERROR 1";
        }
        
        mysql_set_charset('utf8',$this->dbh );
        
        if (mysql_select_db($database, $this->dbh) === false){
            echo "database $database";
            echo " ERROR 2";    
        }
    }
    
    public function __destruct() {
        mysql_close($this->dbh);
    } 
    
    public function query($query) {
        echo "dbadapter query $query  ";
        $result = mysql_query($query);
        
        if ($result === false) {
            echo "Error ";
            echo mysql_error();
        }
        echo "END of query ";
        
        return $result;
    }
    
}

?>
